home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / PGM_TOOL / TPRCDR10 / TPRECDIR.INT < prev    next >
Text File  |  1993-12-26  |  6KB  |  108 lines

  1. { ╔═══════════╤════════════════════════════════════════════════╗
  2.   ║ Programmer│ Tony Papadimitriou                             ║
  3.   ║ Unit      │ TPRecDir (Recursive Directory)                 ║
  4.   ║ Uses      │ Dos                                            ║
  5.   ║ Includes  │ Nothing                                        ║
  6.   ║ Created   │ Saturday, December 18, 1993  8:34 pm           ║
  7.   ║ Updated   │ Sunday, December 26, 1993 11:26 pm             ║
  8.   ║ Language  │ (MSDOS) Turbo Pascal 6.0                       ║
  9.   ║ Purpose   │ Calls a user routine with a file handle based  ║
  10.   ║           │ on the recursive file search parameters given. ║
  11.   ╟───────────┴┬──────── Version History ──────────────────────╢
  12.   ║ 1.00 931218│Original                                       ║
  13.   ║ 1.10 931225│Added MkChDir function                         ║
  14.   ║ 1.20 931226│Added GetMask and GetPath functions            ║
  15.   ╚════════════╧═══════════════════════════════════════════════╝ }
  16. Unit TPRecDir;
  17.  
  18. { ╔════════════════════════════════════════════════════════════╗
  19.   ║        U N I T   I N T E R F A C E   S E C T I O N         ║
  20.   ╚════════════════════════════════════════════════════════════╝ }
  21.  
  22. interface
  23.  
  24. uses
  25.   {$ifdef VER60} {$ifopt G+} CPU286, {$endif} {$endif}
  26.   Dos;
  27.  
  28. var
  29.   errorsFound: Boolean;  { True if there errors during last call to ForEachFileIn }
  30.  
  31. { ╔═══════════╤════════════════════════════════════════════════╗
  32.   ║ Routine   │ ForEachFileIn                                  ║
  33.   ║ Purpose   │ Keep calling routine pointed by userRoutine    ║
  34.   ║           │ until all files have been processed.           ║
  35.   ║           │ Return the number of files processed.          ║
  36.   ║ Note(s)   │ The user routine must be declared FAR and have ║
  37.   ║           │ a header similar to the following:             ║
  38.   ║           │ function User(s: SearchRec): Boolean; far;     ║
  39.   ║           │ This function should return True if there were ║
  40.   ║           │ no problems, and False otherwise.              ║
  41.   ║           │ The s variable will hold the SearchRec of each ║
  42.   ║           │ file that is matched by this routine.          ║
  43.   ║           │ If the userRoutine pointer is NIL then no      ║
  44.   ║           │ user routine will be called, and the routine   ║
  45.   ║           │ will simply return the number of files found.  ║
  46.   ║           │ Forward slashes are allowed in the work path.  ║
  47.   ╚═══════════╧════════════════════════════════════════════════╝ }
  48. function ForEachFileIn(workPath,             { beginning directory, e.g., 'E:\TMP' }
  49.                        fileMask: String;     { file mask, e.g., '*.BAK' }
  50.                        attr: Word;           { file attribute to match }
  51.                        monitorEsc: Boolean;  { if True, an ESC press will cause immediate return }
  52.                        recurseOn: Boolean;   { if True, it will recurse subdirectories }
  53.                        userRoutine: pointer): Longint;
  54.  
  55. { ╔═══════════╤════════════════════════════════════════════════╗
  56.   ║ Routine   │ IsGlobalMask                                   ║
  57.   ║ Purpose   │ Return True if mask passed is equivalent to    ║
  58.   ║           │ '*.*', such as '*??.???' for example.          ║
  59.   ╚═══════════╧════════════════════════════════════════════════╝ }
  60. function IsGlobalMask(mask: String): Boolean;
  61.  
  62. { ╔═══════════╤════════════════════════════════════════════════╗
  63.   ║ Routine   │ IsValidMask                                    ║
  64.   ║ Purpose   │ Return True if mask passed does NOT contain    ║
  65.   ║           │ any of the following characters:               ║
  66.   ║           │ < > = , ; : [ ] / \ +                          ║
  67.   ╚═══════════╧════════════════════════════════════════════════╝ }
  68. function IsValidMask(mask: String): Boolean;
  69.  
  70. { ╔═══════════╤════════════════════════════════════════════════╗
  71.   ║ Routine   │ AttributeMatches                               ║
  72.   ║ Purpose   │ Return True if attr1 and attr2 have any bits   ║
  73.   ║           │ in common.                                     ║
  74.   ╚═══════════╧════════════════════════════════════════════════╝ }
  75. function AttributeMatches(attr1,attr2: Word): Boolean;
  76.  
  77. { ╔═══════════╤════════════════════════════════════════════════╗
  78.   ║ Routine   │ MaskMatches                                    ║
  79.   ║ Purpose   │ Return True if filename can be matched by mask ║
  80.   ║ Note(s)   │ Mask may contain multiple masks delimited by ; ║
  81.   ╚═══════════╧════════════════════════════════════════════════╝ }
  82. function MaskMatches(filename,mask: String): Boolean;
  83.  
  84. { ╔═══════════╤════════════════════════════════════════════════╗
  85.   ║ Routine   │ MkChDir                                        ║
  86.   ║ Purpose   │ Create (if non-existant) dir tree and change   ║
  87.   ║           │ to it. Returns True on success.                ║
  88.   ╚═══════════╧════════════════════════════════════════════════╝ }
  89. function MkChDir(dir: String): Boolean;
  90.  
  91. { ╔═══════════╤════════════════════════════════════════════════╗
  92.   ║ Routine   │ GetMask                                        ║
  93.   ║ Purpose   │ Return the multiple masks from a given argument║
  94.   ╚═══════════╧════════════════════════════════════════════════╝ }
  95. function GetMask(path: String): String;
  96.  
  97. { ╔═══════════╤════════════════════════════════════════════════╗
  98.   ║ Routine   │ GetPath                                        ║
  99.   ║ Purpose   │ Return the path/no masks from a given argument ║
  100.   ╚═══════════╧════════════════════════════════════════════════╝ }
  101. function GetPath(path: String): String;
  102.  
  103. { ╔════════════════════════════════════════════════════════════╗
  104.   ║   U N I T   I M P L E M E N T A T I O N   S E C T I O N    ║
  105.   ╚════════════════════════════════════════════════════════════╝ }
  106.  
  107. implementation
  108.